Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
Correct way to capture `host` portion of fully qualified domain name

I have a hostName string which may or may not be a fully qualified domain name.

hostName = host1.abc.com  OR

hostName = host1

In case hostName is a fully qualified domain name, then I need to capture only the first portion in host

host = host1

I have written the following but it is giving empty string "" when the hostName is not a fully qualified domain name

const host = hostName.substring(0, hostName.indexOf('.'));
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This way it will give the hostname correctly, in any of the 2 scenarios

const host = hostName.split('.')[0];

Or else

const idx = hostName.indexOf('.');

const host = idx > 0 ? hostName.substring(0, idx) : hostName;

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda